package bulk_param.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import bulk_param.controller.AideIndicatifOuvertureController;
import bulk_param.controller.ButtonOuvertureController;
import bulk_param.controller.ColorErrorActivationController;
import bulk_param.controller.RadioButtonCreationController;
import bulk_param.controller.SetSelectedBoxOuvertureController;
import bulk_param.dao.SelectBoxOuverturePointDao;
import bulk_param.modele.JTextFieldLimit;

import com.toedter.calendar.JDateChooser;
import com.toedter.calendar.JTextFieldDateEditor;

public class Open_Contact_Num_View extends JPanel{	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		
	private Font font = new Font("Comic Sans MS", Font.BOLD, 12);
	private Font fontBouton = new Font("Broadway", Font.BOLD, 12);
	private JPanel panelNord;
	private JPanel panelOpenPoint;
	private JPanel contact_Panel;
	private JPanel panelTrafic,panelVoix;;
	public JButton btValider ;
	public JTextFieldDateEditor dateEditor;
	public JDateChooser dateChooser;
	private String selectDate = "Séléction de Date";
	public JRadioButton national, international;
	public JRadioButton fixe_geo,num_09, mobile;
	private ButtonGroup typeTrafic, typeVoix;
	public JLabel lbOperateur,lbPays,lbZABPQ, lbPointRegion, lbActiveDt, lbZNE, lbZLT ;
	public JComboBox<String> cbOperateur, cbPays,cbPointRegion, cbZNE;
	public JTextField txtZABPQ, txtZLT ;
	
	//Liste des contenus combobox
	public ArrayList<String> listOperateurNationalFixe,listOperateurNationalMobile,listPaysFixe,listPaysMobile;
	public ArrayList<String> listZNE,listPointRegionNational,listPointRegionFixeInternational;
	
	public SelectBoxOuverturePointDao selectBoxOuverturePointDao ;
	
	public Open_Contact_Num_View(){
		
	}
	
	public JPanel panelOuverture(){		
		
		//Remplissage des contenue des combobox via BD
        selectBoxOuverturePointDao = new SelectBoxOuverturePointDao();
        selectBoxOuverturePointDao.getConnection();
		listOperateurNationalFixe = selectBoxOuverturePointDao.listOperateurNationalFixe09();
		listOperateurNationalMobile = selectBoxOuverturePointDao.listOperateurNationalMobile();
		listPaysFixe = selectBoxOuverturePointDao.listPaysFixeInternational();
		listPaysMobile = selectBoxOuverturePointDao.listPaysMobInternational();
		listPointRegionFixeInternational = selectBoxOuverturePointDao.listPointRegionInternational();
		listPointRegionNational = selectBoxOuverturePointDao.listPointRegionNational();
		listZNE = selectBoxOuverturePointDao.listZNENational();    
		selectBoxOuverturePointDao.closeConnection();
		
		//Panel Nord
		panelNord = new JPanel();
		panelNord.setLayout(new FlowLayout());
		
		//Panel Open_Point
		panelOpenPoint = new JPanel();
		panelOpenPoint.setLayout(new BorderLayout());
		
		//Type de trafic
		panelTrafic= new JPanel();
		panelTrafic.setPreferredSize(new Dimension(280,120));
		Border titledBorderTrafic = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.getHSBColor(93/360F, 0.57F, 0.60F)), "Type de trafic :", TitledBorder.LEFT, TitledBorder.TOP, font, Color.getHSBColor(93/255F, 0.57F, 0.60F));
		panelTrafic.setBorder(BorderFactory.createTitledBorder(titledBorderTrafic));
		panelTrafic.setLayout(new GridLayout(3,1,10,20));
		national = new JRadioButton("National");
		national.setSelected(true);
		international = new JRadioButton("International");
		typeTrafic =new ButtonGroup();
		typeTrafic.add(national);
		typeTrafic.add(international);
		panelTrafic.add(national);
		panelTrafic.add(international);
		
		//Type de voix
		panelVoix= new JPanel();
		panelVoix.setPreferredSize(new Dimension(280,120));
		Border titledBorderVoix = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.getHSBColor(93/360F, 0.57F, 0.60F)), "Type de voix :", TitledBorder.LEFT, TitledBorder.TOP, font, Color.getHSBColor(93/255F, 0.57F, 0.60F));
		panelVoix.setBorder(BorderFactory.createTitledBorder(titledBorderVoix));
		panelVoix.setLayout(new GridLayout(3,1,10,20));
		fixe_geo = new JRadioButton("Fixe géographique");
		fixe_geo.setSelected(true);
		num_09 = new JRadioButton("Numéro 09");
		mobile = new JRadioButton("Mobile");
		typeVoix =new ButtonGroup();
		typeVoix.add(fixe_geo);
		typeVoix.add(num_09);
		typeVoix.add(mobile);
		panelVoix.add(fixe_geo);
		panelVoix.add(num_09);
		panelVoix.add(mobile);
		
		panelNord.add(panelTrafic);
		panelNord.add(panelVoix);
		
		//GridBagLayout pour les champs d'activation du point ZABPQ
        contact_Panel = new JPanel();
        contact_Panel.setLayout(new GridBagLayout());
        
		// libelle premiere ligne
        
        //Point_region
        GridBagConstraints gridBagConstraintsPointRegion = new GridBagConstraints();
        lbPointRegion = new JLabel("Point Region : ");
        gridBagConstraintsPointRegion.gridx = 1;
        gridBagConstraintsPointRegion.gridy = 0;
        gridBagConstraintsPointRegion.insets = new Insets(10, 5, 10, 5);
        gridBagConstraintsPointRegion.anchor = gridBagConstraintsPointRegion.WEST;
        contact_Panel.add(lbPointRegion, gridBagConstraintsPointRegion);
        
        GridBagConstraints gridBagConstraintsSelectPointRegion = new GridBagConstraints();
        cbPointRegion = new JComboBox<String>();
        cbPointRegion.addItem(null);
        for (int i=0;i<listPointRegionNational.size();i++){
        	cbPointRegion.addItem(listPointRegionNational.get(i));
        }
        cbPointRegion.setPreferredSize(new Dimension(200, 21));
        gridBagConstraintsSelectPointRegion.gridx = 2;
        gridBagConstraintsSelectPointRegion.gridy = 0;
        gridBagConstraintsSelectPointRegion.insets = new Insets(10, 5, 10, 10);
        gridBagConstraintsSelectPointRegion.anchor = gridBagConstraintsSelectPointRegion.WEST;
        contact_Panel.add(cbPointRegion, gridBagConstraintsSelectPointRegion);
        
      //Pays international fixe
        GridBagConstraints gridBagConstraintsPaysFixe = new GridBagConstraints();
        lbPays = new JLabel("Pays : ");
        gridBagConstraintsPaysFixe.gridx = 1;
        gridBagConstraintsPaysFixe.gridy = 1;
        gridBagConstraintsPaysFixe.insets = new Insets(10, 5, 10, 5);
        gridBagConstraintsPaysFixe.anchor = gridBagConstraintsPaysFixe.WEST;
        contact_Panel.add(lbPays, gridBagConstraintsPaysFixe);
        lbPays.setVisible(false);
        
        GridBagConstraints gridBagConstraintsSelectPaysFixe = new GridBagConstraints();
        cbPays = new JComboBox<String>();
        cbPays.addItem(null);
        for (int i=0;i<listPaysFixe.size();i++){
        	cbPays.addItem(listPaysFixe.get(i));
        }
        cbPays.setPreferredSize(new Dimension(150, 21));
        gridBagConstraintsSelectPaysFixe.gridx = 2;
        gridBagConstraintsSelectPaysFixe.gridy = 1;
        gridBagConstraintsSelectPaysFixe.insets = new Insets(10, 5, 10, 10);
        gridBagConstraintsSelectPaysFixe.anchor = gridBagConstraintsSelectPaysFixe.WEST;
        contact_Panel.add(cbPays, gridBagConstraintsSelectPaysFixe);     
        cbPays.setVisible(false);
        
        GridBagConstraints gridBagConstraintsPointZABPQ = new GridBagConstraints();
        lbZABPQ = new JLabel("Point(0ZABPQ) : ");
        lbZABPQ.setPreferredSize(new Dimension(130, 21));
        gridBagConstraintsPointZABPQ.gridx = 3;
        gridBagConstraintsPointZABPQ.gridy = 0;
        gridBagConstraintsPointZABPQ.insets = new Insets(10, 10, 10, 0);
        gridBagConstraintsPointZABPQ.anchor = gridBagConstraintsPointZABPQ.WEST;
        contact_Panel.add(lbZABPQ, gridBagConstraintsPointZABPQ);
        
        GridBagConstraints gridBagConstraintsPoint = new GridBagConstraints();
        txtZABPQ = new JTextField(12);
        txtZABPQ.setDocument(new JTextFieldLimit(7));
        gridBagConstraintsPoint.gridx = 4;
        gridBagConstraintsPoint.gridy = 0;
        gridBagConstraintsPoint.insets = new Insets(10, 10, 10, 5);
        gridBagConstraintsPoint.anchor = gridBagConstraintsPoint.WEST;
        contact_Panel.add(txtZABPQ, gridBagConstraintsPoint);
        
     // libelle deuxieme ligne
      //Operateur National
        GridBagConstraints gridBagConstraintsOperateurs = new GridBagConstraints();
        lbOperateur = new JLabel("Opérateurs : ");
        gridBagConstraintsOperateurs.gridx = 1;
        gridBagConstraintsOperateurs.gridy = 1;
        gridBagConstraintsOperateurs.insets = new Insets(10, 5, 10, 5);
        gridBagConstraintsOperateurs.anchor = gridBagConstraintsOperateurs.WEST;
        contact_Panel.add(lbOperateur, gridBagConstraintsOperateurs);
        
        GridBagConstraints gridBagConstraintsSelectOperateurs = new GridBagConstraints();
        cbOperateur = new JComboBox<String>();
        cbOperateur.addItem(null);
        for (int i=0;i<listOperateurNationalFixe.size();i++){
        	cbOperateur.addItem(listOperateurNationalFixe.get(i));
        }      
        cbOperateur.setPreferredSize(new Dimension(200, 21));
        gridBagConstraintsSelectOperateurs.gridx = 2;
        gridBagConstraintsSelectOperateurs.gridy = 1;
        gridBagConstraintsSelectOperateurs.insets = new Insets(10, 5, 10, 10);
        gridBagConstraintsSelectOperateurs.anchor = gridBagConstraintsSelectOperateurs.WEST;
        contact_Panel.add(cbOperateur, gridBagConstraintsSelectOperateurs);
        
        //Date activation
        GridBagConstraints gridBagConstraintsActiveDt = new GridBagConstraints();
        lbActiveDt = new JLabel("Date d'activation : ");
        gridBagConstraintsActiveDt.gridx = 3;
        gridBagConstraintsActiveDt.gridy = 1;
        gridBagConstraintsActiveDt.insets = new Insets(10, 10, 10, 0);
        gridBagConstraintsActiveDt.anchor = gridBagConstraintsActiveDt.WEST;
        contact_Panel.add(lbActiveDt, gridBagConstraintsActiveDt);
        
        GridBagConstraints gridBagConstraintsTxtActiveDt = new GridBagConstraints();     
        dateChooser = new JDateChooser();
        dateChooser.setDateFormatString("dd/MM/yyyy");
        dateChooser.setPreferredSize(new Dimension(135, 21));
        dateEditor = (JTextFieldDateEditor)dateChooser.getDateEditor();
        dateEditor.setEditable(false);
        dateEditor.setText(selectDate);
        dateEditor.setForeground(Color.gray);
        gridBagConstraintsTxtActiveDt.gridx = 4;
        gridBagConstraintsTxtActiveDt.gridy = 1;
        gridBagConstraintsTxtActiveDt.insets = new Insets(10, 10, 10, 5);
        gridBagConstraintsTxtActiveDt.anchor = gridBagConstraintsTxtActiveDt.WEST;
        contact_Panel.add(dateChooser, gridBagConstraintsTxtActiveDt);
        
        // libelle troiseme ligne
        GridBagConstraints gridBagConstraintsZNE = new GridBagConstraints();
        lbZNE = new JLabel("ZNE(Point Class) : ");
        gridBagConstraintsZNE.gridx = 1;
        gridBagConstraintsZNE.gridy = 2;
        gridBagConstraintsZNE.insets = new Insets(10, 5, 10, 5);
        gridBagConstraintsZNE.anchor = gridBagConstraintsZNE.WEST;
        contact_Panel.add(lbZNE, gridBagConstraintsZNE);
        
        GridBagConstraints gridBagConstraintsSelectZNE = new GridBagConstraints();
        cbZNE = new JComboBox<String>();
        cbZNE.addItem(null);
        for (int i=0;i<listZNE.size();i++){
        	cbZNE.addItem(listZNE.get(i));
        }
        cbZNE.setPreferredSize(new Dimension(200, 21));
        gridBagConstraintsSelectZNE.gridx = 2;
        gridBagConstraintsSelectZNE.gridy = 2;
        gridBagConstraintsSelectZNE.insets = new Insets(10, 5, 10, 10);
        gridBagConstraintsSelectZNE.anchor = gridBagConstraintsSelectZNE.WEST;
        contact_Panel.add(cbZNE, gridBagConstraintsSelectZNE);
        
        GridBagConstraints gridBagConstraintsZLT = new GridBagConstraints();
        lbZLT = new JLabel("ZLT : ");
        gridBagConstraintsZLT.gridx = 3;
        gridBagConstraintsZLT.gridy = 2;
        gridBagConstraintsZLT.insets = new Insets(10, 10, 10, 0);
        gridBagConstraintsZLT.anchor = gridBagConstraintsZLT.WEST;
        contact_Panel.add(lbZLT, gridBagConstraintsZLT);
        
        GridBagConstraints gridBagConstraintsTxtZLT = new GridBagConstraints();
        txtZLT = new JTextField(12);
        txtZLT.setEnabled(false);
        gridBagConstraintsTxtZLT.gridx = 4;
        gridBagConstraintsTxtZLT.gridy = 2;
        gridBagConstraintsTxtZLT.insets = new Insets(10, 10, 10, 5);
        gridBagConstraintsTxtZLT.anchor = gridBagConstraintsTxtZLT.WEST;
        contact_Panel.add(txtZLT, gridBagConstraintsTxtZLT);
        
        //lieblle boutton
        GridBagConstraints gridBagConstraintsbtValider = new GridBagConstraints();
        btValider = new JButton("Valider");
        btValider.setPreferredSize(new Dimension(100,21));
        btValider.setBackground(Color.black);
        btValider.setFont(fontBouton);
        btValider.setForeground(Color.getHSBColor(39,233,255));
        gridBagConstraintsbtValider.gridx = 3;
        gridBagConstraintsbtValider.gridy = 3;
        gridBagConstraintsbtValider.insets = new Insets(10, 5, 10, 5);
        gridBagConstraintsbtValider.anchor = gridBagConstraintsbtValider.WEST;
        contact_Panel.add(btValider, gridBagConstraintsbtValider);
        
        //Panel assemblage
        JPanel assemblage = new JPanel();
        assemblage.setLayout(new BoxLayout(assemblage, BoxLayout.Y_AXIS));
        assemblage.add(panelNord);
        assemblage.add(contact_Panel);       
		
		//ZABPQ OPEN_CONTACT LAYOUT
        
		panelOpenPoint.add(assemblage,BorderLayout.CENTER);
		
		
		//Action sur les radios boutons
		national.addActionListener(new RadioButtonCreationController(this));
		international.addActionListener(new RadioButtonCreationController(this));
		fixe_geo.addActionListener(new RadioButtonCreationController(this));
		num_09.addActionListener(new RadioButtonCreationController(this));
		mobile.addActionListener(new RadioButtonCreationController(this));
		
		//Action Bouton valider
		btValider.addActionListener(new ButtonOuvertureController(this));
		
		//Changement des bordures de textfield en cas d'erreur
		cbOperateur.addMouseListener(new ColorErrorActivationController(this));
		cbPays.addMouseListener(new ColorErrorActivationController(this));
		cbPointRegion.addMouseListener(new ColorErrorActivationController(this));
		cbZNE.addMouseListener(new ColorErrorActivationController(this));
		txtZABPQ.addMouseListener(new ColorErrorActivationController(this));
		dateEditor.addMouseListener(new ColorErrorActivationController(this));
		dateChooser.addMouseListener(new ColorErrorActivationController(this));
		
		//changement de la selectbox
		cbZNE.addActionListener(new SetSelectedBoxOuvertureController(this));
		cbPays.addActionListener(new SetSelectedBoxOuvertureController(this));
		cbPointRegion.addActionListener(new SetSelectedBoxOuvertureController(this));
		cbOperateur.addActionListener(new SetSelectedBoxOuvertureController(this));
		
		//Aide Indicatif 
		txtZABPQ.addMouseListener(new AideIndicatifOuvertureController(this));
		
		
		return panelOpenPoint;
						
	}		
}
